#!/usr/bin/perl -w 
use  strict ;
use Expect ;

#if (@_ < 1 ) {
#    print "### USAGE:   commands\n" ;
#    exit 1 ;
#}



#my $ip=$ENV{ABSIP} ;
my $ip="121.101.220.180" ;
#my $user=$ENV{ABSUSER} ;
my $user="root" ;
#my $passwd=$ENV{ABSPASSWD} ;
my $passwd="ds%^&*()_+1234" ;
#my $port=$ENV{ABSPORT} ;
my $port="35000" ;
#my $timeoutflag=$ENV{ABSSSHTIMEOUT} ;
#my $timeout=$timeoutflag;
#set user "$env(ABSUSER)"
#set passwd "$env(ABSPASSWD)"
#set port "$env(ABSPORT)"
#set timeoutflag "$env(ABSSSHTIMEOUT)"
#set commands [lindex $argv 0]

#set yesnoflag 0
#set timeout $timeoutflag
my $exp = Expect->new;
$exp->log_stdout(0);
$exp = Expect->spawn("ssh -l $user -p $port $ip");
$exp->log_file("output.log", "w");
$exp->expect(2,[
                    qr/password:/i,
                    sub {
                            my $self = shift ;
                            $self->send("$passwd\n");
                            exp_continue;
 
                        }
                ],
                [
                    'connecting (yes/no)',
                    sub {
                            my $self = shift ;
                            $self->send("yes\n");
                         }
                ]
            );
#$exp->interact() if ($exp->expect(undef,'#'));
$exp->send("@ARGV\n") if ($exp->expect(undef,'#'));
$exp->send("exit\n") if ($exp->expect(undef,'#'));
$exp->log_file(undef);
